//
//  VisitorTableViewController.swift
//  sinaWB
//
//  Created by 杨运旺 on 15/11/8.
//  Copyright © 2015年 杨运旺. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    
    /// 用户登录标记
    private var userLogin = UserAccountViewModel.sharedUserAccount.userLogon
    /// 访客视图
    var visitorView : VisitorView?
   
    override func loadView() {
        // 根据用户登录情况，决定显示的根视图
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    
//    override func viewDidAppear(animated: Bool) {
//        super.viewDidAppear(animated)
//        
//        print(visitorView)
//    }
    
    /// 设置访客视图 - 让每一个`小`函数
    private func setupVisitorView(){
        // 替换根视图
        visitorView = VisitorView()
        // 设置代理
        visitorView?.delegate = self
        
        view = visitorView
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
}
// MARK: - 访客视图监听方法
extension VisitorTableViewController:VisitorViewDelegate{
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func visitorViewDidRegister() {
        print("注册")
    }
}
